﻿using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;

namespace SimpleDemo.Controllers
{
    public class FruitsAjaxCheckBoxListController : Controller
    {
        public ActionResult GetItems(IEnumerable<int> keys)
        {
            keys = keys ?? new List<int>();
            var res = Db.Fruits.Select(o =>
                                       new SelectListItem
                                           {
                                               Text = o.Name,
                                               Value = o.Id.ToString(),
                                               Selected = (keys.Contains(o.Id))
                                           });

            return Json(res);
        }
    }
}